//
//  ModelSelectViewController.m
//  CardWarrior
//
//  Created by Tekka Xie on 12-4-24.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "ModelSelectViewController.h"
#import "AudioManager.h"
#import "GameDataManager.h"

@implementation ModelSelectViewController

@synthesize singleModeView;
@synthesize doubleModeView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
        return YES;
    
    return NO;
}

#pragma mark - touches

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = [[event allTouches] anyObject];
    UIImageView *touchView = (UIImageView*)[touch view];
    
    if (touchView.highlighted == NO)
    {
        singleModeView.highlighted = NO;
        doubleModeView.highlighted = NO;
        
        touchView.highlighted = YES;
        
        [[AudioManager sharedInstance] PlaySFX:@"SelectSFX"];
    }
    else
    {
        if (touchView == singleModeView)
        {
            //进入单人模式
            [[GameDataManager sharedInstance] setGameCurrentMode:1];
        }
        else
        {
            //进入双人模式
            [[GameDataManager sharedInstance] setGameCurrentMode:2];
        }
        
        [self performSegueWithIdentifier:@"SegueToRoleSelectViewController" sender:self];
        [[GameDataManager sharedInstance] setWhoIsSelecting:1];
        [[GameDataManager sharedInstance] saveData];
        [[AudioManager sharedInstance] PlaySFX:@"ConfirmSFX"];
    }
}

@end
